﻿//===============================================================================
// Copyright © 2011 Allen Lee
// This code released under the terms of the MIT License (http://iridescent.codeplex.com/license)
//===============================================================================
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using Iridescent.Models;

namespace Iridescent.Utils
{
    public class AssignmentToBrushConverter : IValueConverter
    {
        object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var assignment = value as Assignment;

            if (assignment == null)
            {
                return (SolidColorBrush)Application.Current.Resources["PhoneAccentBrush"];
            }

            if (assignment.IsCompleted)
            {
                return new SolidColorBrush(Colors.Green);
            }
            else
            {
                if (assignment.DueDate < DateTime.Today)
                {
                    return new SolidColorBrush(Colors.Red);
                }
                else
                {
                    return new SolidColorBrush(Color.FromArgb(255, 27, 161, 226));
                }
            }
        }

        object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
